package org.hxyjs.dao.impl;

import org.hxyjs.dao.CheforderDao;


import org.hxyjs.entity.Cheforder;
import org.hxyjs.mapper.CheforderMapper;
import org.hxyjs.mapper.CheforderMapper;
import org.hxyjs.page.PageInfo;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("cheforderDao")//一般实现类不会直接生成默认对象名 而是使用 接口的默认对象名


public class CheforderDaoImpl implements CheforderDao {
    @Resource //autowired 会装配能够直接扫描到的对象  resource spring容器运行的时候才找到需要的对象  注入
    private CheforderMapper cheforderMapper;


//    public List<Cheforder> selectOrderWithUserByCno(String cno) throws Exception {
//        return cheforderMapper.selectOrderWithUserByCno(cno);
//    }


    @Override
    public List<Cheforder> getCheforderByPage(PageInfo pageInfo) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("currPage", pageInfo.getCurrPage());
        map.put("pageSize", pageInfo.getPageSize());
        int itemCount = (int) cheforderMapper.countByExample(null);
        pageInfo.setItemCount(itemCount);
        return cheforderMapper.getCheforderByPage(map);
    }

    @Override
    public List<Cheforder> getAllCheforders() throws Exception {
        return cheforderMapper.selectByExample(null);
    }

    @Override
    public Cheforder getCheforderByCuno(String cuno) throws Exception {
        return cheforderMapper.selectByPrimaryKey(cuno);
    }

    @Override
    public Integer deleteCheforderByCuno(String cuno) throws Exception {
        return cheforderMapper.deleteByPrimaryKey(cuno);
    }

    @Override
    public Integer updateCheforderByCuno(Cheforder cheforder) throws Exception {
        return cheforderMapper.updateByPrimaryKey(cheforder);
    }

    @Override
    public Integer addCheforder(Cheforder cheforder) throws Exception {
        return cheforderMapper.insertSelective(cheforder);
    }
}